package team.pwyseckill.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import team.pwyseckill.consts.RbmConsts;

import java.util.HashMap;
import java.util.Map;


@Configuration
public class RbmConfig {
    @Bean
    public Queue queue01(){
        return new Queue(RbmConsts.SEC_QUEUE);
    }


    //    秒杀活动开始前
    @Bean
    public CustomExchange seckllExchange(){
        Map<String, Object> arguments = new HashMap<>(1);
        arguments.put("x-delayed-type", "direct");
        return new CustomExchange(RbmConsts.SECKILL_EX,"x-delayed-message",true,false,arguments);
    }

    @Bean
    public Queue queueSeckill(){
        return new Queue(RbmConsts.SECKILL_EX_QUEUE,true);
    }
    @Bean
    public Binding bindingQueueSeckill(){
        return BindingBuilder.bind(queueSeckill()).to(seckllExchange()).with(RbmConsts.SECKILL_EC_QUEUE_RK).noargs();
    }

//    //    秒杀活动结束
//    @Bean
//    public CustomExchange seckllEndExchange(){
//        Map<String, Object> arguments = new HashMap<>(1);
//        arguments.put("x-delayed-type-end", "direct-end");
//        return new CustomExchange(RbmConsts.SECKILLEND_EX,"x-delayed-message-end",true,false,arguments);
//    }
//
//    @Bean
//    public Queue queueSeckillEnd(){
//        return new Queue(RbmConsts.SECKILLEND_EX_QUEUE,true);
//    }
//    @Bean
//    public Binding bindingQueueSeckillEnd(){
//        return BindingBuilder.bind(queueSeckillEnd()).to(seckllEndExchange()).with(RbmConsts.SECKILLEND_EC_QUEUE_RK).noargs();
//    }
}
